﻿using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using RNNLibrary;

namespace RNN
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = "双色球.csv";
            List<string> contentList = File.ReadAllLines(file).ToList();
            List<TwoColorBall> ballList = new List<TwoColorBall>();
            foreach(var content in contentList)
            {
                string[] temp = content.Split(',');
                TwoColorBall ball = new TwoColorBall();
                ball.Issue = temp[0].ToInt();
                string[] temp1 = temp[1].Split(' ');
                ball.Blue = temp1[6].ToDecimal();
                ball.RedOne = temp1[0].ToInt();
                ball.RedTwo = temp1[1].ToInt();
                ball.RedThree = temp1[2].ToInt();
                ball.RedFour = temp1[3].ToInt();
                ball.RedFive = temp1[4].ToInt();
                ball.RedSex = temp1[5].ToInt();
                ballList.Add(ball);
            }

            Console.WriteLine(ballList.Count);
            List<TwoColorBall> trainList = ballList.GetRange(0, 11);
            List<TwoColorBall> testList = ballList.GetRange(11, 101);
            OriginalRNN rnn = new OriginalRNN(trainList.Take(trainList.Count - 1).Select(b => (decimal)b.Blue).ToList(), trainList.Skip(1).Select(b => (decimal)b.Blue).ToList());

            for (int i = 0; i<1000;i++)
            {
                rnn.Train();
                Console.WriteLine(rnn.LossVal);
            }
            int accurateCount = 0;
            List<decimal> ylist=rnn.Prediction(testList.Select(b => (decimal)b.Blue).ToList());
            for (int i=0;i< ylist.Count;i++)
            {
                decimal y = Math.Ceiling(ylist[i]);
                if (y == testList[i + 1].Blue)
                {
                    accurateCount++;
                }
                Console.WriteLine("预测值：" + y + "。实际值：" + testList[i+1].Blue);
            }

            Console.WriteLine("总数：" + testList.Count + "。准确数：" + accurateCount + "。准确率：" + ((double)accurateCount / testList.Count)*100+"%");
            Console.ReadLine();
        }
    }
}
